const fp = require("lodash/fp");
const fs = require("fs");
// monad (单子)
class IO {
    static of(value) {
        return new IO(value);
    }
    constructor(fn) {
        this._value = fn;
    }
    map(fn) {
        return new IO(fp.flowRight(fn, this._value));
    }
    join() {
        return this._value();
    }
    floatMap(fn) {
        return this.map(fn).join();
    }
}

const readFile = function (fileName) {
    return new IO(function () {
        return fs.readFileSync(fileName, "utf-8");
    });
};

const print = function (x) {
    return new IO(function () {
        console.log(x);
        return x;
    });
};

let r = readFile("package.json").map(fp.toUpper).floatMap(print).join();
console.log(r);
